/**
 * @file     longestCommonSubstring.cpp
 * @author   DuYong
 * @date     2021-03-06
 * @times	 #####
 */
/*
A = "ABCD", B = "CBCE"
return 2.
*/
int longestCommonSubstring(string& A, string& B) {
	if(A.empty() || B.empty()) {
        return 0;
	}   
    
    int lcs = 0, lcs_temp = 0;
    for(int i = 0; i < A.size(); ++i) {
        for(int j = 0; j < B.size(); ++j) {
            lcs_temp = 0;
            while((i+lcs_temp < A.size()) && 
                  (j+lcs_temp < B.size()) && 
                  (A[i+lcs_temp] == B[j+lcs_temp])) {
                ++lcs_temp;
            }
            
            // update lcs
            if(lcs_temp > lcs) {
                lcs = lcs_temp;
            }
        }
    }
    
    return lcs;
}